import Immutable from 'immutable';

import { CHANGESWITCH } from './actionTypes'

const defaultState = Immutable.fromJS({
  // 方法一：checked: localStorage.getItem('checked') === 'true' ? true : false
  // 方法二：
  checked: JSON.parse(localStorage.getItem('checked'))
})

const reducer = (state = defaultState, action) => {
  switch(action.type) {
    case CHANGESWITCH: 
      return state.set('checked', action.checked)
      // return {
      //   checked: action.checked
      // }
    default: return state
  }
}

export default reducer